package com.example.hotel.web;

import com.example.hotel.common.JsonResult;
import com.example.hotel.common.PassToken;
import com.example.hotel.service.LoginService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin
@RequestMapping("login")

public class LoginController {
    @Autowired
    LoginService loginService;
    @ApiOperation(value = "登录")
    @PassToken
    @GetMapping("findLogin")
    public JsonResult findLogin(String login_name,String login_pwd){
        try {
            String token = loginService.findLogin(login_name,login_pwd);
            if(token!=null){
                return JsonResult.ok(token);
            }else {
                return JsonResult.fail(1234,"登录失败");
            }
        }catch (Exception e){
            e.printStackTrace();
            return JsonResult.fail();
        }
    }
}
